package com.suixinsanren.design.compound.study.demo04;

/**
 * simulator()接收工厂对象，由工厂给他生产鸭子，而非自己new
 */
public class DuckSimulator {

    public static void main(String[] args) {
        DuckSimulator simulator = new DuckSimulator();
        AbstractDuckFactory duckFactory = new CountingDuckFactory();
        simulator.simulator(duckFactory);
    }

    public void simulator(AbstractDuckFactory duckFactory) {
        Quackable redHeadDuck = duckFactory.createRedHeadDuck();
        Quackable duckCall = duckFactory.createDuckCall();
        Quackable rubberDuck = duckFactory.createRubberDuck();
        GooseAdapter goose = new GooseAdapter(new Goose());
        System.out.println("--------Duck Simulator : With Composite Flocks--------");

        Flock flockOfDucks = new Flock();

        flockOfDucks.add(redHeadDuck);
        flockOfDucks.add(duckCall);
        flockOfDucks.add(rubberDuck);
        flockOfDucks.add(goose);

        Flock flockOfMallards = new Flock();

        Quackable mallardOne = duckFactory.createMallardDuck();
        Quackable mallardTwo = duckFactory.createMallardDuck();
        Quackable mallardThree = duckFactory.createMallardDuck();
        Quackable mallardFour = duckFactory.createMallardDuck();

        flockOfMallards.add(mallardOne);
        flockOfMallards.add(mallardTwo);
        flockOfMallards.add(mallardThree);
        flockOfMallards.add(mallardFour);

        flockOfDucks.add(flockOfMallards);

        System.out.println("--------Duck Simulator : Whole Flock Simulation--------");
        simulator(flockOfDucks);

        System.out.println("--------Duck Simulator : Mallard Flock Simulation--------");
        simulator(flockOfMallards);

    }


    public void simulator(Quackable duck) {
        duck.quack();
    }
}
